package com.fzl.springblogdemo.controller;

import com.fzl.springblogdemo.pojo.dataobject.BlogInfo;
import com.fzl.springblogdemo.pojo.request.UserLoginRequest;
import com.fzl.springblogdemo.pojo.request.UserRegisterRequest;
import com.fzl.springblogdemo.pojo.response.UserInfoResponse;
import com.fzl.springblogdemo.pojo.response.UserLoginResponse;
import com.fzl.springblogdemo.service.impl.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/user")
@RestController
@Slf4j
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;
@RequestMapping("/login")
    public UserLoginResponse login(@RequestBody @Validated UserLoginRequest userLoginRequest) {
    log.info("用户名"+userLoginRequest.getUserName());
    return userService.checkPassword(userLoginRequest);
}
@RequestMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull(message = "userid不能为空") Integer userId) {
        log.info("获取用户信息"+userId);
        return userService.getUserInfo(userId);
    }
    @RequestMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull(message = "blogId不能为空") Integer blogId) {
        log.info("获取作者信息"+blogId);
        return userService.getAuthorInfo(blogId);
    }

    @RequestMapping("/register")
    public Boolean register(@RequestBody @Validated UserRegisterRequest userRegisterRequest) {
        log.info("用户注册信息"+userRegisterRequest);
        return userService.register(userRegisterRequest);
    }

}
